$(function(){
	var dataTable = $("#bpChannelDataTable").DataTable({
		"ajax": {
			"url": '/bpChannel/list',
			"data": function(data){
				data.createTime = $("#createTime").val();
				data.status = $("#status").val();
			}
		},
		"ordering": false,
		"columns": [
//			{
//				"data": "id",
//				"className": "text-center sign-col",
//				"render": function(data, type, row, meta){
//					return '<input type="checkbox" name="pk" value="' + data + '" onclick="checkOne()"/>';
//				}
//			},
			{"data": "channelSort"},
			{
				"data": function(obj){
					var text = '';
					if(obj.icon != null && obj.icon != ''){
						text +='<img alt="" src="http://39.105.119.87:8088'+obj.icon+'" width="40" height="40"/>&nbsp;';
					} else {
						text = '-';
					}
					return text;
				}
			},
			{"data": "channelCode"},
			{"data": "channelName"},
			{
				"data": function(obj){
					return new Date(obj.createTime).Format("yyyy-MM-dd hh:mm:ss");
				} 
			},
			{
				"data": function(obj){
					var text = '';
					if (obj.status == '0') {
						text = '停用';
					} else if (obj.status == '1') {
						text = '启用';
					}
					return text;
				}
			},
			{"data": "remarks"},
			{
				"data": "id",
				"className": "operate-col",
				"data": function(data){
//					var html = '<button type="button" onclick="edit(\''+ data.id +'\')" class="btn btn-sm btn-warning right-5"><i class="fa fa-edit"></i></button>';
//					var html = '<button type="button" onclick="view(\''+ data.id +'\')" class="btn btn-sm btn-info"><i class="fa fa-search"></i></button>';
					var html = '';
					if(data.status == '1'){
						html += '<button type="button" onclick="changeStatus(\''+ data.id +'\', \'0\')" class="btn btn-sm btn-info">停用</button>';
					} else {
						html += '<button type="button" onclick="changeStatus(\''+ data.id +'\', \'1\')" class="btn btn-sm btn-info">启用</button>';
					}
					return html;
				}
			}
		]
	});
	
	$('#searchBtn').click(function(){
		dataTable.ajax.reload();
	});
	
	$('#resetBtn').click(function(){
		$('#bpChannelSearchForm')[0].reset();
		dataTable.ajax.reload();
	});
	
	$('#addBtn').click(function(){
		forwardPage('/bpChannel/bpChannel');
	});
	
//	$('#delBtn').click(function(){
//		ajaxBySelecteRows(dataTable,'/bpChannel/delete','确定要删除？');
//	});
	
	// 日期
	$('.datepicker').datetimepicker({
		language: 'zh-CN',
		format: 'yyyy-mm-dd',
		autoclose: true,
		todayBtn: true,
		clearBtn:true,
		minView: 2
	});
});

//function edit(id){
//	forwardPage('/bpChannel/bpChannel?id='+id);
//}

//function view(id){
//	forwardPage('/bpChannel/view?id='+id);
//}
function changeStatus(id, status){
	$.ajax({
		type: 'post',
		url: '/bpChannel/changeStatus',
		data: {id: id, status: status},
		dataType: 'json',
		success: function(response){
			modalAlert(response.message);
			$("#bpChannelDataTable").DataTable().ajax.reload();
		}
	});
}